<script setup>
import { ref, reactive, onMounted, onBeforeUnmount } from "vue";
import { Search } from "@element-plus/icons-vue";
import lodash from "lodash";
import api from "@/api";

const robotData = reactive({
  list: [],
  cacheList: [],
  keywords: "",
  curIndex: -1,
  statisticUrl: "",
  Detail: "",
  curVideoUrl: "",
});

api.robot.getRobotInfos().then((res) => {
  robotData.statisticUrl = res.statisticUrl;
  robotData.cacheList = res.data;

  robotData.list = lodash.cloneDeep(robotData.cacheList);
  if (res.data && res.data.length > 0) {
    robotData.Detail = res.data[0].detail;
    robotData.curVideoUrl = res.data[0].videoUrl;
    robotData.curIndex = 0;
  }
});

onMounted(() => {});

const handleClick = (item, index) => {
  if (robotData.curIndex == index) return;
  robotData.curIndex = index;
  robotData.Detail = item.detail;
  robotData.curVideoUrl = item.videoUrl;
};

//筛选
const searchHandleClick = function () {
  if (robotData.keywords === "") {
    robotData.list = lodash.cloneDeep(robotData.cacheList);
  } else {
    robotData.list = [];
    robotData.cacheList.forEach((item) => {
      if (item.robotType.indexOf(robotData.keywords) !== -1) {
        robotData.list.push(item);
      }
    });
  }

  if (robotData.list.length > 0) {
    robotData.Detail = robotData.list[0].detail;
    robotData.curIndex = 0;
    robotData.curVideoUrl = robotData.list[0].videoUrl;
  }
};
</script>

<template>
  <div class="robotContainer">
    <div class="d-l">
      <div class="searchPanel">
        <el-input
          v-model="robotData.keywords"
          placeholder="请输入关键词"
          size="small"
        >
          <template #append
            ><el-button @click="searchHandleClick" :icon="Search"></el-button
          ></template> </el-input
        ><br />
        <img src="@/assets/images/ibe/total.png" style="width: 20px" />
        <span
          ><span class="total">共计</span
          ><span class="colorText">{{ robotData.list.length }}</span
          >款</span
        >
      </div>
      <div class="listContainer">
        <ul>
          <li v-for="(item, index) in robotData.list" :key="index">
            <div
              :class="[
                'listItem',
                robotData.curIndex == index ? 'activeItem' : '',
              ]"
              @click="handleClick(item, index)"
            >
              <div class="thumb">
                <el-image
                  crossorigin="anonymous"
                  style="width: 50px; height: 30px"
                  :src="robotData.statisticUrl + item.imgUrl"
                  fit="fill"
                />
              </div>
              <div class="info">
                <span class="titleSpan">{{ item.robotType }}</span
                ><br />
                <div class="description">{{ item.description }}</div>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="d-r">
      <div class="deviceVideo">
        <video :src="robotData.statisticUrl + robotData.curVideoUrl" crossorigin="anonymous" controls loop muted>
        </video>
      </div>
      <div class="deviceTable">
        <div class="title">
          <span>产品优势</span>
        </div>
        <div class="info">
          <span>{{ robotData.Detail }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.robotContainer {
  position: relative;
  display: flex;
  width: 100%;
  height: calc(100vh - 80px);
  font-family: SourceHanSansSC;
  color: #656565;
  overflow-x: hidden;
  overflow-y: auto;

  .d-l {
    width: 23%;
    height: calc(100vh - 85px);
    min-height: 835px;
    margin-left: 8px;
    border: 1px solid #dce3ef;
    box-shadow: 2px 2px 0px 0px rgba(236, 238, 252, 0.32);
    border-radius: 6px;

    .searchPanel {
      margin-top: 15px;
      margin-bottom: 10px;
      padding-left: 20px;

      .total {
        padding: 0px 5px;
      }

      :deep .el-input {
        width: 80%;
      }

      .colorText {
        font-size: 30px;
        font-family: Source Han Sans SC;
        font-weight: 500;
        color: #4095ff;
        padding-right: 5px;
      }
    }

    .listContainer {
      height: calc(100vh - 200px);
      min-height: 730px;
      overflow-y: auto;
      overflow-x: hidden;

      .listItem {
        width: 95%;
        height: 88px;
        margin: 0 auto;
        margin-bottom: 10px;
        border-bottom: 1px solid #dce3ef;
        box-sizing: border-box;
        display: flex;
        align-items: center;

        .thumb {
          width: 87px;
          margin-right: 10px;
          background-repeat: no-repeat;
          background-size: 100% 100%;
          text-align: center;
          img {
            width: 100%;
            height: 100%;
          }
        }

        .info {
          width: 280px;

          .titleSpan {
            font-size: 16px;
            font-family: Source Han Sans SC;
            font-weight: 500;
            color: #424242;
            line-height: 25px;
            font-weight: bold;
          }
          .description {
            width: 100%;
            height: 40px;
            overflow: hidden;
            -webkit-line-clamp: 2;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
          }
        }
      }

      .activeItem {
        background-color: #e8e9fb;
      }
    }

    .deviceMaintain {
      width: 100%;
      height: 648px;
      border: 1px solid #dce3ef;
      box-shadow: 2px 2px 0px 0px rgba(236, 238, 252, 0.32);
      border-radius: 6px;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      background-image: url("@/assets/images/ibe/deviceMatain.png");
    }
  }

  .d-r {
    width: 75%;
    margin-left: 16px;
    height: calc(100vh - 95px);

    .deviceVideo {
      width: 100%;
      height: 580px;
      border: 1px solid #dce3ef;
      box-shadow: 2px 2px 0px 0px rgba(236, 238, 252, 0.32);
      border-radius: 6px;
      margin-bottom: 8px;
      video {
        width: 100%;
        height: 100%;
        object-fit: fill;
      }
    }

    .deviceTable {
      width: 100%;
      //height: 254px;
      height: 245px;
      border: 1px solid #dce3ef;
      box-shadow: 2px 2px 0px 0px rgba(236, 238, 252, 0.32);
      border-radius: 6px;

      .info {
        padding: 0 20px;
        font-size: 14px;
        font-family: Source Han Sans SC;
        font-weight: 500;
        color: #656565;
        line-height: 33px;
        font-weight: bold;
      }
    }
  }

  .modalDevice {
    position: absolute;
    top: 15%;
    left: 15%;
    background-color: white;
  }
}

.title {
  width: 100px;
  height: 20px;
  border-left: 3px #8f93f7 solid;
  font-weight: bold;
  padding-left: 10px;
  margin: 15px;
}

#deviceChart {
  width: 100%;
  max-width: 441px;
  height: 335px;
}
</style>